﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Secondhand_Book_Trade
{
    public partial class Display : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int bookId = Convert.ToInt32(Request.QueryString["BookID"]);
                string sql = "SELECT CoverUrl, Title, Price, Description FROM Books WHERE BookID=@BookID";
                using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Secondhand_book_tradeConnectionString"].ToString()))
                {
                    SqlCommand cmd = new SqlCommand(sql, conn);
                    cmd.Parameters.AddWithValue("@BookID", bookId);
                    conn.Open();
                    SqlDataReader dr = cmd.ExecuteReader();
                    if (dr.Read())
                    {
                        // 关键：用 Src 属性
                        imgBook.Src = dr["CoverUrl"].ToString();
                        lblTitle.InnerText = dr["Title"].ToString();
                        lblPrice.InnerText = "￥" + Convert.ToDecimal(dr["Price"]).ToString("F2");
                        lblDescription.InnerText = dr["Description"].ToString();
                    }
                }
            }
        }
        protected void btnFavorite_Click(object sender, EventArgs e)
        {
            if (Session["UserID"] == null)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>requireLogin();</script>");
                return;
            }
            // 收藏逻辑
        }

        protected void btnComment_Click(object sender, EventArgs e)
        {
            if (Session["UserID"] == null)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>requireLogin();</script>");
                return;
            }
            // 评论逻辑
        }

        protected void btnBuy_Click(object sender, EventArgs e)
        {
            if (Session["UserID"] == null)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>requireLogin();</script>");
                return;
            }
            // 购买逻辑
        }
    }
}